<template>
	<view class="shareBonusManage-container">
		<!-- <view class="date-choose-box">
			<image src="@/static/index/calendar.png" mode="widthFix" class="calendar-icon"></image>
			<picker mode="date" fields="month"  :value="date" @change="bindDateChange" :end="currenDate">
				<view class="select-input" v-if="date">{{date}}</view>
				<view class="select-input" v-else>选择日期</view>
			</picker>
		</view> -->

		<view class="bonus-item" v-for="(item,index) in list" :key="index">
			<view class="date">{{item.divideDate}}
				<text v-if="item.lastMouthBalance<0">（{{getPreviousMonth(item.divideDate)}}月利润结余{{item.lastMouthBalance}}）</text>
			</view>
			<view class="top-overview flexWrapNo">
				<view class="item">
					<text class="value">{{item.totalIncome||0}}</text>
					<text class="label">总收入</text>
				</view>
				<view class="item" @tap="goPage('/micro-shareholder/costManage')">
					<text class="value special">{{item.totalCost||0}}</text>
					<text class="label">总成本</text>
				</view>
				<view class="item">
					<text class="value">{{item.totalProfit||0}}</text>
					<text class="label">总利润</text>
				</view>
			</view>
			
			<view class="dividend-box">
				<view class="dividend-item flexWrapNo"  @tap="goPage('/micro-shareholder/shareBonusRecord')">
					应分总分红 <text class="special">{{item.totalDivide||0}}</text>
				</view>
				<view class="inner-box flexWrapNo">
					<view class="dividend-item flexWrapNo">每股应分红 <text>{{item.eachSharesDivide||0}}</text></view>
					<view class="dividend-item flexWrapNo">应分总股数 <text>{{item.totalShares||0}}</text></view>
				</view>
			</view>
			
			<view class="grant-box flexWrapNo">
				<view class="grant-item flexWrapNo" @tap="goPage('/micro-shareholder/shareBonusRecord?type=2')">
					已发放分红 <text class="special">{{item.issuedDivide||0}}</text>
				</view>
				<view class="grant-item flexWrapNo">已发放总股数 <text>{{item.issuedShares||0}}</text></view>
				<view class="grant-item flexWrapNo" @tap="goPage('/micro-shareholder/shareBonusRecord?type=1')">
					待发放分红 <text class="special">{{item.unissuedDivide||0}}</text>
				</view>
				<view class="grant-item flexWrapNo">未发放总股数 <text>{{item.unissuedShares||0}}</text></view>
			</view>
		</view>
		
		<uni-load-more v-if="showLoadStatus" :status="status" :size="14" :content-text="contentText" />
		<view class="quesheng" v-if="showEmpty">
			<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png"></image>
		</view>
		
		<!--操作指引悬浮按钮 -->
		<guideline :path="'micro-shareholder/shareBonusManage'"></guideline>
	</view>
</template>

<script>
	export default{
		data(){
			const currentDate = this.getDate({
				format: true
			})
			return{
				date:currentDate,
				currenDate:currentDate,
				
				list:[],
				page: 1,
				size: 10,
				showEmpty: true,
				showLoadStatus: false,
				more: true,
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中...',
					contentnomore: '已经到底了~~'
				},
				status: 'loading',
			}
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh() {
			this.freshList()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 500)
		},
		onReachBottom() {
			if (this.more) {
				this.getList()
			}
		},
		methods:{
			// 获取日期 --当月
			getDate(type) {
				const date = new Date();
				date.setDate(date.getDate());
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				// return `${year}-${month}-${day}`
				return `${year}-${month}`
			},
			
			// 选择时间
			// bindDateChange(e) {
			// 	this.date = e.target.value
			// 	this.getList()
			// },
			
			//  根据时间字符串获取上一月的月份
			getPreviousMonth(dateString) {
				const date = new Date(dateString);
				const currentMonth = date.getMonth() + 1;
				const previousMonth = new Date(date.getFullYear(), date.getMonth(), 0);
				return previousMonth.getMonth() + 1; // 上个月的月份
			},
			
			freshList(){
				this.page = 1
				this.more = true
				this.status = 'loading'
				this.list = []
				this.getList();
			},
			
			// 获取分红数据
			getList(){	
				this.$request.post(this.$api.divideInfo, {
					storeId:uni.getStorageSync('store_id'),
					pageNum:this.page++,  //当前页数
					pageSize:this.size,  //当前条数
				}, {
					isJava: true
				}).then(res => {
					if(res.code==200){
						let {
							data = {}
						} = res;
						let newArray = data.list
						
						if (newArray.length == 0 && this.page == 2) {
							this.showEmpty = true
							this.showLoadStatus = false
							this.more = false // 不能再次请求了
							return false;
						} else {
							this.showLoadStatus = true
							this.more = true
							this.showEmpty = false
							this.status = 'loading'
						}
						if (newArray.length < this.size) { // 说明没有更多数据
							this.status = 'noMore'
							this.more = false
							this.showEmpty = false
						}
						this.list = this.list.concat(newArray);
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.shareBonusManage-container{
		padding: 32rpx;
	}
	.date-choose-box{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		gap:20rpx;
		font-size: 28rpx;
		.calendar-icon{
			width: 36rpx;
		}
		picker{
			font-size: 28rpx;
		}
	}

	.bonus-item{
		margin-bottom: 50rpx;
		.date{
			color: #FD8926;
			font-size: 28rpx;
		}
		.top-overview{
			padding: 30rpx 40rpx;
			border-bottom: 1rpx solid rgba(255,255,255,0.3);
			justify-content: space-between;
			gap: 40rpx;
			.item{
				display: flex;
				flex-direction: column;
				align-items: center;
				.value{
					color:rgba(255,255,255,1);
					font-size: 30rpx;
					font-weight: bold;
				}
				.label{
					margin-top: 4rpx;
					color:rgba(255,255,255,0.8);
					font-size: 26rpx;
				}
				
			}
		}
		
		.dividend-box{
			margin-top: 30rpx;
			padding:0 30rpx 30rpx 30rpx;
			border-bottom: 1rpx solid rgba(255,255,255,0.3);
			.dividend-item{
				color:rgba(255,255,255,0.8);
				font-size: 26rpx;
				justify-content: center;
				>text{
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 10rpx;
				}
			}
			.inner-box{
				margin-top: 10rpx;
				justify-content: space-between;
			}
		}
		.grant-box{
			margin-top: 30rpx;
			padding: 0 30rpx;
			flex-wrap: wrap;
			gap: 20rpx 0;
			.grant-item{
				color:rgba(255,255,255,0.8);
				font-size: 26rpx;
				width: 50%;
				justify-content: flex-start;
				&:nth-child(2n){
					justify-content: flex-end;
				}
				>text{
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 10rpx;
				}
			}
		}
		
		.special{
			color:#26BCFD !important;
		}
	}
	
	.quesheng{
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		image{
			width: 476upx;
			height: 280upx;
		}
	}
	
</style>